<?php
/**
 * Reports
 *
 * reports.php
 * @author Hector Lucero
 * @version 1.0
 * @copyright Hector Lucero, 13 October, 2011
 * @package 1.0
 **/

class Reports extends CI_Controller {
    
    public function __construct() {
        parent::__construct();

        $this->load->model("menu_model");
        $this->load->model("reports_model");

        //Only allow logged in users to access this controller
        if($this->session->userdata('logged_in') == FALSE) redirect('login');
    }

    function index() {
        $this->generate_report();
    }

    function generate_report() {
        $this->load->library('fpdf');
        $this->fpdf->Open();
        $color = "col0";
        $s0 = 10;
        $s1 = 30;
        $s2 = 30;
        $w = array($s0, $s1, $s2);
        $h = 4;
        $s = .62;
        $subtitle = array('ID', 'NOMBRE','APELLIDO');
    
        $title = array();
        $title[] = "MIS AMIGOS";
    
        $author = $this->session->userdata('real_name');
    
        $this->fpdf->SetW($w);
        $this->fpdf->SetH($h);
        $this->fpdf->SetS($s);
        $this->fpdf->SetTitle($title);
        $this->fpdf->SetSubTitle($subtitle);
        $this->fpdf->SetAuthor($author);
        $this->fpdf->AddPage('P');
    
        /* start body */
        $query = $this->db->get('amigos');
        if($query->num_rows() > 0) {
            foreach($query->result() as $row) {
                $id = $row->id;
                $nombre = $row->nombre;
                $apellido = $row->apellido;
                $this->fpdf->Cell($s0, $h, $id, 0, 0, 'L');
                $this->fpdf->Cell(2, $h, "", 0, 0, 'L');
                $this->fpdf->Cell($s1, $h, $nombre, 0, 0, 'L');
                $this->fpdf->Cell(2, $h, "", 0, 0, 'L');
                $this->fpdf->Cell($s2, $h, $apellido, 0, 0, 'L');
            }
        }
        /* end body   */
    
        $this->fpdf->Output();
    
        $this->fpdf->Close();
    }
}        
/* end of file */
